/******************************************************************/
/*                                                                */
/*  Winpooch : Windows Watchdog                                   */
/*  Copyright (C) 2004-2005  Benoit Blanchon                      */
/*                                                                */
/*  This program is free software; you can redistribute it        */
/*  and/or modify it under the terms of the GNU General Public    */
/*  License as published by the Free Software Foundation; either  */
/*  version 2 of the License, or (at your option) any later       */
/*  version.                                                      */
/*                                                                */
/*  This program is distributed in the hope that it will be       */
/*  useful, but WITHOUT ANY WARRANTY; without even the implied    */
/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       */
/*  PURPOSE.  See the GNU General Public License for more         */
/*  details.                                                      */
/*                                                                */
/*  You should have received a copy of the GNU General Public     */
/*  License along with this program; if not, write to the Free    */
/*  Software Foundation, Inc.,                                    */
/*  675 Mass Ave, Cambridge, MA 02139, USA.                       */
/*                                                                */
/******************************************************************/


/******************************************************************/
/* Includes                                                       */
/******************************************************************/

// module's interface
#include "AboutWnd.h"

// standard headers
#include <windows.h>
#include <tchar.h>

// project's headers
#include "Language.h"
#include "ProjectInfo.h"
#include "Version.h"


/******************************************************************/
/* Internal constants                                             */
/******************************************************************/

#define WC_ABOUTWND TEXT("AboutWnd")

static TCHAR szVersion[] = 
  TEXT("Winpooch version %s, Copyright (C) 2005 Benoit Blanchon") ;

static TCHAR szLicense[] =
  TEXT ("Winpooch comes with ABSOLUTELY NO WARRANTY.\n"
	"This is free software, and you are welcome to redistribute "
	"it under certain conditions.\nFor details, please read "
	"LICENCE text file provided with this software.") ;


/******************************************************************/
/* Internal functions                                             */
/******************************************************************/

LRESULT CALLBACK _AboutWnd_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ;


/******************************************************************/
/* Exported function : RegisterClass                              */
/******************************************************************/

BOOL AboutWnd_RegisterClass (HINSTANCE hInstance) 
{
  WNDCLASS wndclass ;

  wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  wndclass.lpfnWndProc   = _AboutWnd_WndProc ;
  wndclass.cbClsExtra    = 0 ;
  wndclass.cbWndExtra    = 0 ;
  wndclass.hInstance     = hInstance ;
  wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1) ;
  wndclass.lpszMenuName  = NULL ;
  wndclass.lpszClassName = WC_ABOUTWND ;

  return 0!=RegisterClass (&wndclass) ;
}


/******************************************************************/
/* Exported function : CreateWindow                               */
/******************************************************************/

HWND AboutWnd_CreateWindow (HINSTANCE hInstance, HWND hwndParent)
{  
  return CreateWindowEx (WS_EX_CLIENTEDGE,
			 WC_ABOUTWND, NULL,
			 WS_CHILD,
			 CW_USEDEFAULT, CW_USEDEFAULT,
			 CW_USEDEFAULT, CW_USEDEFAULT, 
			 hwndParent, NULL, hInstance, NULL) ;
}


/******************************************************************/
/* Internal function : WndProc                                    */
/******************************************************************/

LRESULT CALLBACK _AboutWnd_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  static HWND hwndVersion, hwndLicense, hwndTranslation ;
  TCHAR	szBuffer[1024] ;

  switch (message)
    {
    case WM_CREATE:

      hwndVersion = CreateWindow (TEXT("static"), NULL, WS_CHILD|WS_VISIBLE,
				  10, 10, 600, 30, hwnd, NULL, NULL, NULL) ;
      
      hwndTranslation = CreateWindow (TEXT("static"), NULL, WS_CHILD|WS_VISIBLE,
				      10, 40, 600, 30, hwnd, NULL, NULL, NULL) ;    

      hwndLicense = CreateWindow (TEXT("static"), NULL, WS_CHILD|WS_VISIBLE,
				  10, 70, 600, 200, hwnd, NULL, NULL, NULL) ;   
      
    case WM_LANGUAGECHANGED:

      if( Language_IsLoaded() )
	wsprintf (szBuffer, STR(_VERSION_S), TEXT(APPLICATION_VERSION_STRING)) ;
      else
	wsprintf (szBuffer, szVersion, TEXT(APPLICATION_VERSION_STRING)) ;
      SetWindowText (hwndVersion, szBuffer) ;

      SetWindowText (hwndLicense, STR_DEF(_LICENSE, szLicense)) ;
      
      if( Language_IsLoaded() )
	SetWindowText (hwndTranslation, STR(_TRANSLATION_BY)) ;
      else
	SetWindowText (hwndTranslation, TEXT("")) ;

      return 0 ;
    }

  return DefWindowProc (hwnd, message, wParam, lParam) ;
}
